package com.rj.bd.reservation.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rj.bd.reservation.entity.Reservation;
import com.rj.bd.reservation.service.IReservationService;

@Controller
@RequestMapping("/reservation")
public class ReservationController {
	
	@Autowired
    IReservationService reservationService;
    
    @ResponseBody
    @RequestMapping("/queryyuyue")
    public Map<String, Object> queryUser(@RequestBody Reservation reservation , Page<Reservation> page) {
    	
    	System.out.println(reservation);
    	
    	System.out.println("current"+reservation.getCurrent());
    	
    	page.setCurrent(reservation.getCurrent());
    	
    	Map<String, Object> map = new HashMap<String, Object>();
    	
    	page.setSize(2);
    	
    	List<Reservation> list = reservationService.selectAll(page, reservation);
    	System.out.println("list---------->"+list);
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("list",list);
        map.put("page",page.getCurrent());//当前页数
        map.put("pagetotla",page.getPages());//总页数
    	return map;
    }

    
    @ResponseBody
    @RequestMapping("/queryjiezhong")
    public Map<String, Object> queryWeijiezhong( Page<Reservation> page,@RequestBody  Reservation reservation) {
    	
    	Map<String, Object> map = new HashMap<String, Object>();
    	page.setCurrent(reservation.getCurrent());
    	
    	page.setSize(2);
    	List<Reservation> list = reservationService.selectjiezhong(page, reservation);
    	System.out.println("list---------->"+list);
        map.put("code",200);
        map.put("msg","查询成功");
        map.put("list",list);
        map.put("page",page.getCurrent());//当前页数
        map.put("pagetotla",page.getPages());//总页数
    	return map;
    }
    
    @ResponseBody
    @RequestMapping("/add")
    public Map<String, Object> add (@RequestBody Reservation reservation) {
        System.out.println("-->reservation" + reservation.toString());
        
        reservationService.save(reservation);
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code",200);
        map.put("msg","添加成功");
        return map;
    }
    
    @ResponseBody
    @RequestMapping("/edit")
    public Map<String, Object> edit (@RequestBody Reservation reservation) {
        System.out.println("-->reservation" + reservation.toString());
        
        reservationService.edit(reservation);
        
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code",200);
        map.put("msg","修改成功");
        return map;
    }
    
    
    @ResponseBody
    @RequestMapping("/delete")
    public Map<String, Object> delete(@RequestBody Reservation reservation) {
    	System.out.println(reservation.getRId()+":"+reservation.getPId());
        reservationService.delete(reservation.getRId(),reservation.getPId());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code",200);
        map.put("msg","删除成功");
        return map;
    }
}
